 /**
 * 逻辑、功能相关描述: <br>
 *
 * @author 付湘辉  <br>
 * 编写日期：2008-8-12  <br>
 */
package com.ce.pms.charge.dao.impl;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.hibernate.Query;
import org.springframework.util.Assert;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.charge.dao.ITransactionDao;
import com.ce.pms.charge.model.AbstractTrans;
import com.ce.pms.charge.model.AccountDomain;
import com.ce.pms.charge.vo.ChargeDetailSearchVO;
import com.ce.pms.charge.vo.DepositTransSearchVO;
import com.ce.pms.common.annotation.AssociatedPrecinctQuery;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.util.SqlConfig;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.core.support.Page;

/**
 * 	名称: com.ce.pms.charge.dao.impl.TransactionDaoImpl <br>
 *  交易Dao实现
 *
 * @author  付湘辉  <br>
 * Created on： 2008-8-12 <br>
 * @author <br>
 * update on： <br>
 * why: <br>
 */
public class TransactionDaoImpl extends PmsBaseDaoImpl<AbstractTrans> implements
		ITransactionDao {

	private final String FRONT_SQL_CONFIG_PATH = "FrontCashier.xml";
	/**
	 * 功能描述: 查询交易表(FEE_TRANSACTION)当天收费记录数 <br>
	 * @param clazz 交易类型
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-7  <br>
	 * Edit author: 付湘辉 <br>
	 * Edit on:2008-12-30    <br>
	 * Why: 为统一调用，在收费凭证Dao已有相同功能实现    <br>
	 */
	@Deprecated
	public Integer getCurDayChargeTimes(String clazz){
		Integer count = 0;
		if (BlankUtil.isBlank(clazz)) {
			return 0;
		}
		SqlConfig config = new SqlConfig(FRONT_SQL_CONFIG_PATH);
		StringBuffer sql = new StringBuffer(config.getSql("CurDayChargeTimes"));
		Query query = super.createSQLQuery(sql.toString(), clazz);
		Object obj = query.uniqueResult();
		count = ((BigInteger)obj).intValue();
		return count;
	}

	/**
	 * 功能描述: 获取出盘锁定状态的交易数量 <br>
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-10-8  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public Integer getOutLocakTransactionCount(){
		return this.getTransactionCountByStatus(SysrefcodeDO.FEE_TRANSACTION_STATUZ_LOCKED);
	}

	/**
	 * 功能描述: 根据主交易ID 查找支付方式及金额 <br>
	 * @param transId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-10-9  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public List getPayListByTransId(Long transId){
		StringBuffer queryStr = new StringBuffer();
		queryStr.append(" SELECT FTR.CREDIT, ");
		queryStr.append("   (select src.SYS_REF_NAME  ");
		queryStr.append("     from SYS_REF_CODE src   ");
		queryStr.append("     where src.SYS_REF_CODE ='FEE_BUSINESS_CODE_PAY_METHOD'  ");
		queryStr.append("           and src.SYS_REF_VALUE =FBC.PAY_METHOD  ) PAY_METHOD ");
		queryStr.append(" from FEE_TRANSACTION FTR  ");
		queryStr.append(" LEFT JOIN FEE_TRA_R_TRA FTRT ON FTRT.TRANSACTION_ID2 = FTR.TRANSACTION_ID ");
		queryStr.append(" LEFT JOIN FEE_BUSINESS_CODE FBC ON FTR.BIZ_CODE_ID = FBC.BIZ_CODE_ID ");
		queryStr.append(" LEFT JOIN FEE_PERIOD FPE ON FTR.PERIOD_ID = FPE.PERIOD_ID ");
		queryStr.append(" WHERE ( FTR.TRANSACTION_ID = ? or ");
		queryStr.append("   FTR.TRANSACTION_ID = ANY   ");
		queryStr.append("      (SELECT FTRT.TRANSACTION_ID2  ");
		queryStr.append("       FROM FEE_TRA_R_TRA FTRT  ");
		queryStr.append("       JOIN FEE_TRANSACTION FTR ON FTRT.TRANSACTION_ID1 = FTR.TRANSACTION_ID ");
		queryStr.append("       WHERE  FTRT.TRANSACTION_ID1 = ? and FTRT.RELATION_TYPE= '"+SysrefcodeDO.FEE_TRA_R_TRA_RELATION_TYPE_MULTIPLEPAY+"' )) ");
		queryStr.append("   and FBC.PAY_METHOD <> '006' ");
		Query query =super.createSQLQuery(queryStr.toString(), new Object[]{transId,transId});

		return query.list();
	}

	/**
	 * 功能描述:查询押金子账户的相关押金收款交易分页列表，
	 * 使用depositTransSearchVO中subAccountId条件进行查询  <br>
	 * @param depositTransSearchVO
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2009-1-9  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public Page queryDepositTransVOByPage(DepositTransSearchVO depositTransSearchVO){
		Assert.notNull(depositTransSearchVO);
		Long subAccountId = depositTransSearchVO.getSubAccountId();

		String hql = "from AbstractTrans at where at.bindingAccount.id=?";
		
		return super.pagedQueryByPageNo(hql, depositTransSearchVO.getPageNo(), depositTransSearchVO.getPageSize(), new Object[]{subAccountId});
	}
	
	/**
	 * 功能描述: 获取指定子账户和交易状态的交易数量 <br>
	 * @param subAccountId 子账户id
	 * @param status 交易状态
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-10-8  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public Long getTransactionCountByIdStatus(Long subAccountId, String status){
		String queryStr="SELECT count(atr.id) FROM AbstractTrans atr WHERE atr.bindingAccount.id=? AND atr.statuz=? ";
		Query query = super.createQuery(queryStr, subAccountId,status);
		Object obj = query.uniqueResult();
		Long result = (Long)obj;
		return result;
	}

	/**
	 * 功能描述: 得到指定子账户和交易类型的交易记录列表 <br>
	 * @param subAccountId
	 * @param clazz 交易类型
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-7  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public List<AbstractTrans> getTransBysubaccountIdAdnclazz(Long subAccountId,String clazz){
		String hql = "from AbstractTrans att where att.bindingAccount.id=? and att.clazz=? ";
		List<AbstractTrans> list = super.createQuery(hql, subAccountId,clazz).list();
		if (BlankUtil.isBlank(list)) {
			return null;
		}
		return list;
	}

	/**
	 * 功能描述:根据收费凭证 ID 查询主交易信息  <br>
	 * @param voucherId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-10-8  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public List getTransByVoucherId(Long voucherId) {
		StringBuffer queryStr = new StringBuffer();
		queryStr.append(" select tra.TRANSACTION_ID,CONCAT(bus.BIZ_CODE ,'-', bus.DESCRIPTION), per.PERIOD, tra.CREDIT ,tra.BIZ_CODE_ID, ");
		queryStr.append(" (select src.SYS_REF_NAME ");
		queryStr.append("   from SYS_REF_CODE src   ");
		queryStr.append("   where src.SYS_REF_CODE = 'FEE_BUSINESS_CODE_PAY_METHOD'  ");
		queryStr.append("   and src.SYS_REF_VALUE =bus.PAY_METHOD  ) PAY_METHOD ,tra.REMARK,");
		queryStr.append(" fci.ITEM_NAME ,tra.SYSDATE,bus.PAY_METHOD as PAY_METHOD_CODE ");
		queryStr.append(" from FEE_TRANSACTION tra ");
		queryStr.append(" join FEE_PERIOD  per on tra.PERIOD_ID  = per.PERIOD_ID ");
		queryStr.append(" join FEE_BUSINESS_CODE bus on  tra.BIZ_CODE_ID =bus.BIZ_CODE_ID ");
		queryStr.append(" left  join FEE_CHARGE_ITEM fci ON fci.BIZ_CODE_ID = bus.BIZ_CODE_ID ");
		queryStr.append(" where tra.CLAZZ_CODE <> '006' and  tra.VOUCHER_ID = ? ");
		Query query =super.createSQLQuery(queryStr.toString(), new Object[]{voucherId});

		return query.list();
	}

	/**
	 * 功能描述: 得到指定帐户下交易数量 <br>
	 * @param accountDo
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-2  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public Long getTransCountByAccount(AccountDomain accountDo){
		return this.getTransCountByAccount(accountDo.getAccountId());
	}

	/**
	 * 功能描述: 得到指定帐户id下交易数量 <br>
	 * @param accountId 帐户id
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-2  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public Long getTransCountByAccount(Long accountId){
		String hql = "select count(tra.id) from AbstractTrans tra where tra.bindingAccount.account.id=? ";
		Object obj = super.createQuery(hql, accountId).uniqueResult();
		if (BlankUtil.isBlank(obj)) {
			return 0l;
		}
		Long count = (Long)obj;
		return count;
	}

	/**
	 * 功能描述:根据主交易ID 查找支付关系的子交易  <br>
	 * @param transId
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-10-8  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public List getVoucherSubtransByTransId(Long transId,String sortStr){
		StringBuffer queryStr = new StringBuffer();
		queryStr.append("  SELECT FTR.TRANSACTION_ID,  ");
		queryStr.append("         CONCAT(FBC.BIZ_CODE, '-', FBC.DESCRIPTION) TRANSNAME,  ");
		queryStr.append("         FPE.PERIOD,  ");
		queryStr.append("         SUM(FTR.DEBIT),  ");
		queryStr.append("         FTR.BIZ_CODE_ID,  ");
		queryStr.append("         (select src.SYS_REF_NAME from SYS_REF_CODE src where src.SYS_REF_CODE =  ");
		queryStr.append("          'FEE_BUSINESS_CODE_PAY_METHOD' and src.SYS_REF_VALUE = FBC.PAY_METHOD)  ");
		queryStr.append("           PAY_METHOD,  ");
		queryStr.append("         FTR.REMARK,  ");
		queryStr.append("         FCI.ITEM_NAME,  ");
		queryStr.append("         FTR.SYSDATE,  ");
		queryStr.append("         FBC.PAY_METHOD  ");
		queryStr.append("  from FEE_TRANSACTION FTR  ");
		queryStr.append("       LEFT JOIN FEE_TRA_R_TRA FTRT ON FTRT.TRANSACTION_ID2 = FTR.TRANSACTION_ID  ");
		queryStr.append("       LEFT JOIN FEE_BUSINESS_CODE FBC ON FTR.BIZ_CODE_ID = FBC.BIZ_CODE_ID  ");
		queryStr.append("       LEFT JOIN FEE_PERIOD FPE ON FTR.PERIOD_ID = FPE.PERIOD_ID  ");
		queryStr.append("       LEFT JOIN FEE_CHARGE_ITEM FCI ON FCI.BIZ_CODE_ID = FBC.BIZ_CODE_ID  ");
		queryStr.append("  WHERE (FTRT.TRANSACTION_ID1 = ?   ");
		queryStr.append("  		OR  ");
		queryStr.append("         FTRT.TRANSACTION_ID1 = ANY (  ");
		queryStr.append("  			SELECT FTRT.TRANSACTION_ID2   ");
		queryStr.append("        		FROM FEE_TRA_R_TRA FTRT JOIN FEE_TRANSACTION FTR ON FTRT.TRANSACTION_ID1 = FTR.TRANSACTION_ID   ");
		queryStr.append("         	WHERE FTRT.TRANSACTION_ID1 = ? and  FTRT.RELATION_TYPE in ('001', '002', '003', '005'))  ");
		queryStr.append("         OR   ");
		queryStr.append("         	FTRT.TRANSACTION_ID1 = ANY (  ");
		queryStr.append("  			SELECT FTRT.TRANSACTION_ID2   ");
		queryStr.append("         	FROM FEE_TRA_R_TRA FTRT JOIN FEE_TRANSACTION FTR ON FTRT.TRANSACTION_ID1 = FTR.TRANSACTION_ID   ");
		queryStr.append("         	WHERE FTRT.TRANSACTION_ID1 = ANY (  ");
		queryStr.append("  				SELECT FTRT.TRANSACTION_ID2   ");
		queryStr.append("        			FROM FEE_TRA_R_TRA FTRT JOIN FEE_TRANSACTION FTR ON FTRT.TRANSACTION_ID1 = FTR.TRANSACTION_ID  ");
		queryStr.append("         		WHERE FTRT.TRANSACTION_ID1 = ?   ");
		queryStr.append("                 and  FTRT.RELATION_TYPE in ('001', '002', '003', '005'))   ");
		queryStr.append("                 and  FTRT.RELATION_TYPE in ('001', '002', '003', '005'))  ");
		queryStr.append("         )  ");
		queryStr.append("  and FTRT.RELATION_TYPE in ('001', '002', '003', '005') and FTR.STATUZ = '002'  ");

		queryStr.append("  GROUP BY  FTR.PERIOD_ID, FTR.BIZ_CODE_ID ");

		if (sortStr == null || "".equals(sortStr)){
			queryStr.append(" ORDER BY FPE.PERIOD desc ");
		}else if ("period asc".equals(sortStr)){
			queryStr.append(" ORDER BY FPE.PERIOD asc ");
		}else if ("period desc".equals(sortStr)){
			queryStr.append(" ORDER BY FPE.PERIOD desc ");
		}

		Query query =super.createSQLQuery(queryStr.toString(), new Object[]{transId,transId,transId});

		return query.list();
	}



	/**
	 * 功能描述:查询指定的房间指定周期是否有出盘锁定状态的交易，如果有则返回true<br>
	 * @param houseid
	 * @param periodId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-11-5<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Boolean isHouseTransactionLocked(Long houseid,Long periodId){
		String hql="SELECT count(tran) FROM DebitTransDomain tran where tran.statuz=? and tran.house.keyword=? and tran.period.keyword=?";
		Query query=createQuery(hql, new Object[]{SysrefcodeDO.FEE_TRANSACTION_STATUZ_LOCKED,houseid,periodId} );
		return ((Long)query.uniqueResult())>0;
	}

	/**
	 * 功能描述: 查询指定应收交易id的其下子交易金额列表 <br>
	 * @param transId 交易id
	 * @param relationType 交易关系类型001,002,003
	 * @param withoutLatefee 是否排除滞纳金
	 * @param status 交易状态
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-9  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public List<BigDecimal> queryDebitSubTransDebitList(Long transId,String relationType,boolean withoutLatefee, String status){
		List<BigDecimal> list  = new ArrayList<BigDecimal>();
		if (BlankUtil.isBlank(transId)) {
			return list;
		}
		SqlConfig config = new SqlConfig(this.FRONT_SQL_CONFIG_PATH);
		//装配查询费用明细原生SQL语句
		StringBuffer sql = new StringBuffer(config.getSql("chargeDebitSubTransDebitList"));

		List<Object> paramList = new ArrayList<Object>();
		int i=0;

        paramList.add(i++, transId);
		if (!BlankUtil.isBlank(relationType)) {//查指定关系类型子交易
			sql.append(config.getSql("chargeDebitAdjustTransSumConDesignType"));
            paramList.add(i++, transId);
			paramList.add(i++, relationType);
            paramList.add(i++, relationType);
		}else if (withoutLatefee) {//不查滞纳金
			sql.append(config.getSql("chargeDebitAdjustTransSumConNoLatefee"));
		}else if (!withoutLatefee) {//查所有子交易，包括滞纳金
            paramList.add(i++, transId);
			sql.append(config.getSql("chargeDebitAdjustTransSumConAll"));
		}
        if (!BlankUtil.isBlank(status)) {//指定交易状态
            sql.append(config.getSql("chargeDebitAdjustTransSumConStatus"));
            paramList.add(i++, status);
        }
		Query query =super.createSQLQuery(sql.toString(), paramList.toArray());

		list = query.list();

		return list;
	}

	/**
	 * 功能描述: 查询支付明细信息，如果是多重支付，返回子支付信息 <br>
	 * 注意：返回的page分页对象list数据中是Object[]，结果中应收交易全是已缴状态 <br>
	 * [0]：交易id TRANSACTION_ID<br>
	 * [1]：应收交易金额 DEBIT<br>
	 * [2]：实收交易金额 CREDIT<br>
	 * [3]：交易名称(BIZ_CODE+'-'+DESCRIPTION 交易码+'-'+交易描述 )<br>
	 * [4]：收费周期(PERIOD 如：200808)<br>
	 * [5]：记账日期 即创建日期SYSDATE<br>
	 * [6]：交易类型，CLAZZ_CODE<br>
	 * [7]：父交易id，M_TRANS_ID<br>
	 * @param payTransId
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-16  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public List<Object[]> queryPayDetailList(Long payTransId){

		List<Object[]> list  = new ArrayList<Object[]>();
		if (BlankUtil.isBlank(payTransId)) {
			return list;
		}
		SqlConfig config = new SqlConfig(FRONT_SQL_CONFIG_PATH);
		StringBuffer sql = new StringBuffer(config.getSql("chargePayDetailList"));

		Query query = super.createSQLQuery(sql.toString(), payTransId,payTransId);
		list = query.list();

		return list;
	}

	/**
	 * 功能描述:查询指定帐户的预交款的交易<br>
	 * @param accountId
	 * @param pageNo
	 * @param pageSize
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-14<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Page queryPrePayTrans(Long accountId,int pageNo,int pageSize){
		StringBuffer hql=new StringBuffer();
		hql.append("FROM AbstractTrans att WHERE 1=1 " )
		.append(" AND att.bindingAccount.account.accountId=? ")
		.append(" AND att.bindingAccount.subAccountId=(" )
		.append("SELECT pay.subAccountId FROM PrePayAccountDomain pay " )
		.append("WHERE pay.account.accountId=att.bindingAccount.account.accountId)");

		return this.pagedQueryByPageNo(hql.toString(), pageNo, pageSize, new Object[]{accountId});
	}

	/**
	 * 功能描述: 查询指定子账户的费用明细信息 <br>
	 * <ul>查询规则：
	 * <li>根据参数searchVo中所含有的字段的值判断；
	 * 必须指定searchVo中subAccountId，
	 * 应该注意当isPreviousPeriod字段被设为true值时，
	 * 表示指定了一个以往的收费周期，
	 * 此时查询指定收费周期的所有衍生交易，其余条件不变。</li>
	 * </ul>
	 * 注意：返回的page分页对象list数据中是Object[] <br>
	 * [0]：交易id TRANSACTION_ID<br>
	 * [1]：子账户id SUB_ACCOUNT_ID<br>
	 * [2]：交易金额 DEBIT 或 CREDIT<br>
     * [3]：交易类型 CLAZZ_CODE<br>
	 * [4]：交易状态(STATUZ，如果是实收交易则是"-")<br>
	 * [5]：来源产权房id HOUSE_ID<br>
	 * [6]：收费标准当前版本id STA_HIS_ID<br>
	 * [7]：凭 证id VOUCHER_ID<br>
	 * [8]：交易名称(BIZ_CODE+'-'+DESCRIPTION 交易码+'-'+交易描述 )<br>
	 * [9]：收费周期(PERIOD 如：200808)<br>
	 * [10]：交易摘要，即备注字段 REMARK<br>
	 * [11]：记账日期 即创建日期SYSDATE<br>
	 * [12]：消费日期，INPUT_DATE<br>
	 * [13]：操作人id CREATOR<br>
	 * [14]：所属主交易id TRANSACTION_ID1<br>
	 * @param searchVo
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-9  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public List<Object[]> queryTransactionBy(ChargeDetailSearchVO searchVo){
		List<Object[]> list  = new ArrayList<Object[]>();
		if (BlankUtil.isBlank(searchVo) || BlankUtil.isBlank(searchVo.getSubAccountId())) {
			return list;
		}
		SqlConfig config = new SqlConfig(this.FRONT_SQL_CONFIG_PATH);
		//装配查询费用明细原生SQL语句
		StringBuffer sql = new StringBuffer(config.getSql("chargeDetailList"));
		List<Object> paramList = new ArrayList<Object>();
		int i=0;
		paramList.add(i++, searchVo.getSubAccountId());

		if (!BlankUtil.isBlank(searchVo.getPeriodId())) {//指定了收费周期
			sql.append(config.getSql("chargeDetailListPeriodCon"));
			paramList.add(i++, searchVo.getPeriodId());
		}
		//处理状态参数
		i = dealStatuzParam(searchVo, config, sql, paramList, i);

		if (!BlankUtil.isBlank(searchVo.getPeriodId())) {//指定了收费周期
			// 指定了以往的收费周期
			if (searchVo.isPreviousPeriod()) {
				sql.append(config.getSql("chargeDetailListPreviousPeriodCon"));
				paramList.add(i++, searchVo.getSubAccountId());
				paramList.add(i++, searchVo.getPeriodId());

				i = dealStatuzParam(searchVo, config, sql, paramList, i);

				sql.append("))");
			}
		}

		Query query =super.createSQLQuery(sql.toString(), paramList.toArray());

		list = query.list();

		return list;
	}

	/**
	 * 功能描述:批量更新交易的状态<br>
	 * @param transactionIds
	 * @param status<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-27<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void updateTransactionStatus(List<Long> transactionIds, String status) {
		String sql="UPDATE FEE_TRANSACTION SET STATUZ=? WHERE TRANSACTION_ID=?";
		List<Object[]> parameters=new ArrayList<Object[]>();
		for(Long tid : transactionIds){
			parameters.add(new Object[]{status,tid});
		}
		executeSQLBatch(sql, parameters);
	}

	/**
	 * 功能描述:批量更新交易指定子帐户且状态为出盘锁定的状态<br>
	 * @param status key 子帐户ID，value 状态
	 * Create author:罗军林<br>
	 * Create on:2008-9-27<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void updateTransactionStatus(Map<Long,String> status) {
		String sql="UPDATE FEE_TRANSACTION SET STATUZ=? WHERE SUB_ACCOUNT_ID=? AND STATUZ=?";
		List<Object[]> parameters=new ArrayList<Object[]>();
		for(Long tid : status.keySet()){
			parameters.add(new Object[]{status.get(tid),tid,SysrefcodeDO.FEE_TRANSACTION_STATUZ_LOCKED});
		}
		executeSQLBatch(sql, parameters);
	}

	/**
	 * 功能描述:批量更新指定主交易的从属交易状态为主交易状态<br>
	 * @param masterIds<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-7<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void updateTransactionStatusByMasterId(List<Long> masterIds){
		String sql="UPDATE FEE_TRANSACTION SET STATUZ=(SELECT a.STATUZ FROM (SELECT STATUZ FROM FEE_TRANSACTION WHERE TRANSACTION_ID=?) a) WHERE M_TRANS_ID=? AND STATUZ='001'";
		List<Object[]> parameters=new ArrayList<Object[]>();
		for(Long tid : masterIds){
			parameters.add(new Object[]{tid,tid});
		}
		executeSQLBatch(sql.toString(), parameters);
	}

	/** 功能描述:  <br>
	 * @param searchVo
	 * @param config
	 * @param sql
	 * @param paramList
	 * @param i
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-18  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private int dealStatuzParam(ChargeDetailSearchVO searchVo, SqlConfig config, StringBuffer sql, List<Object> paramList, int i) {
		if (!BlankUtil.isBlank(searchVo.getStatuz())) {//指定状态
			if (searchVo.getOnlyDebit()) {//只查应收
				sql.append(config.getSql("chargeDetailListStatuzConOnlyDebit"));
			}else{
				sql.append(config.getSql("chargeDetailListStatuzCon"));
			}
			paramList.add(i++, searchVo.getStatuz());
		}
		return i;
	}

	/**
	 * 功能描述: 获取指定状态的交易数量 <br>
	 * @param status 状态
	 * @return
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-10-8  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	@AssociatedPrecinctQuery(alias = "atr", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 1=1",property4Precinct="period.chargePrecinct.keyword")
	private Integer getTransactionCountByStatus(String status){
		String queryStr="SELECT count(atr.id) FROM AbstractTrans atr WHERE 1=1 AND atr.statuz=? ";
		Query query = super.createQuery(queryStr, status);
		Object obj = query.uniqueResult();
		Integer result = ((Long)obj).intValue();
		return result;
	}

}
